#!/bin/bash



if [ -n "$1" ] ; then

  data_date=$1

else

  data_date=`date -d "-1 days" +%F`

fi



sql="

insert into table jtp_app_dws.dws_event_log_session_agg partition (dt = '$data_date')

select

    deviceid,

    devicetype,

    sessionid,

    province,

    city,

    count(*),

    max(\`timestamp\`) - min(\`timestamp\`),

    min(\`timestamp\`)

from jtp_app_dwd.dwd_event_log_detail

where dt = '$data_date'

group by deviceid,devicetype,

sessionid,province,city;

"

/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "${sql}"